package com.huawei.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: liu.cheng.su
 * @Time: 2023/12/18 0018 4:10
 * @Description:
 */
public class Code15 {
    public static void main(String[] args) {
        int[] nums = {-4, -2, 1, -5, -4, -4, 4, -2, 0, 4, 0, -2, 3, 1, -5, 0};
//        int[] nums = {0,0, 0};
        Code15 code15 = new Code15();
        code15.threeSum(nums);
    }

    public List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> ans = new ArrayList<>();
        return ans;
    }


    public List<List<Integer>> threeSum2(int[] nums) {
        List<List<Integer>> ans = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length; j++) {
                if (i != j) {
                    int k = (nums[i] + nums[j]) * -1;
                    if (numsExistK(nums, k, i, j)) {
                        List<Integer> list = new ArrayList<>();
                        list.add(nums[i]);
                        list.add(nums[j]);
                        list.add(k);
                        if (listExist(ans, list)) {
                            continue;
                        }
                        ans.add(list);
                    }
                }
            }
        }
        return ans;
    }

    private boolean numsExistK(int[] nums, int k, int i, int j) {
        for (int h = 0; h < nums.length; h++) {
            if (nums[h] == k
                    && (h != i)
                    && h != j) {
                return true;
            }
        }
        return false;
    }


    private boolean listExist(List<List<Integer>> ans, List<Integer> list) {
        if (ans.size() != 0) {
            for (int i = 0; i < ans.size(); i++) {
                List<Integer> each = ans.get(i);
                if (each.contains(list.get(0))
                        && each.contains(list.get(1))) {
                    return true;
                }
            }
        }
        return false;
    }
}
